nanopyx.liquid

The liquid module contains the core functionality of the liquid engine.

The liquid engine is a NanoPyx library specialized in adaptive processing, where the member classes are able to benchmark themselves and compare their performance for several implementations of the same functionality (OpenCL, Cython, Numba, etc.).

>>> from nanopyx.liquid import MandelbrotBenchmark
>>> mb = MandelbrotBenchmark()
>>> values = mb.benchmark(64) # doctest: +SKIP
 1"""
 2The liquid module contains the core functionality of the liquid engine.
 3
 4The liquid engine is a NanoPyx library specialized in adaptive processing, where the member classes are able to
 5benchmark themselves and compare their performance for several implementations of the same functionality (OpenCL,
 6Cython, Numba, etc.).
 7
 8>>> from nanopyx.liquid import MandelbrotBenchmark
 9>>> mb = MandelbrotBenchmark()
10>>> values = mb.benchmark(64) # doctest: +SKIP
11"""
12
13# flake8: noqa: F401
14
15import os
16import warnings
17import platform
18
19from .__njit__ import njit_works
20from .__opencl__ import cl, cl_array, opencl_works, print_opencl_info, devices
21from ._le_interpolation_bicubic import ShiftAndMagnify as BCShiftAndMagnify
22from ._le_interpolation_bicubic import ShiftScaleRotate as BCShiftScaleRotate
23from ._le_interpolation_catmull_rom import ShiftAndMagnify as CRShiftAndMagnify
24from ._le_interpolation_catmull_rom import ShiftScaleRotate as CRShiftScaleRotate
25from ._le_interpolation_lanczos import ShiftAndMagnify as LZShiftAndMagnify
26from ._le_interpolation_lanczos import ShiftScaleRotate as LZShiftScaleRotate
27from ._le_interpolation_nearest_neighbor import ShiftAndMagnify as NNShiftAndMagnify
28from ._le_interpolation_nearest_neighbor import ShiftScaleRotate as NNShiftScaleRotate
29from ._le_mandelbrot_benchmark import MandelbrotBenchmark
30from ._le_radiality import Radiality
31from ._le_radial_gradient_convergence import RadialGradientConvergence
32from ._le_roberts_cross_gradients import GradientRobertsCross
33from ._le_esrrf import eSRRF as eSRRF_ST
34from ._le_convolution import Convolution as Convolution2D
35from ._le_DUMMY import DUMMY
36
37from multiprocessing import current_process
38
39if current_process().name == 'MainProcess':
40        
41    import logging
42    logger = logging.getLogger(__name__)
43    logger.setLevel(logging.DEBUG)
44    fh = logging.FileHandler(f'{__name__}.log')
45    fh.setLevel(logging.DEBUG)
46    formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
47    fh.setFormatter(formatter)
48    logger.addHandler(fh)
49
50    # OS INFO
51    os_msg = "\n" + "=" * 60 + "\nOS INFORMATION\n"
52    os_msg += "=" * 60 + "\n"
53    os_msg += "OS:  " + platform.platform()  + "\n"
54    os_msg += "Architecture: " + platform.machine() + "\n"
55        
56    # CPU INFO
57    # TODO this can be done with shell commands on a platform dependent manner or external libraries
58    cpu_msg = "\n" + "=" * 60 + "\nCPU INFORMATION\n"
59    cpu_msg += "=" * 60 + "\n"
60    cpu_msg += "CPU:  " + platform.processor()  + "\n"
61
62
63    # RAM INFO
64    # TODO this can be done with shell commands on a platform dependent manner or external libraries
65    ram_msg = "\n" + "=" * 60 + "\nRAM INFORMATION\n"
66    ram_msg += "=" * 60 + "\n"
67    ram_msg += "RAM:  " + "TBD"  + "\n"
68
69    # GPU INFO
70    if opencl_works():
71        gpu_msg = print_opencl_info()
72    else:
73        gpu_msg = "\n" + "=" * 60 + "\n NO PYOPENCL SUPPORT\n"
74        gpu_msg += "=" * 60 + "\n"
75
76    # PYTHON INFO
77    py_msg = "\n" + "=" * 60 + "\nPYTHON INFORMATION\n"
78    py_msg += "=" * 60 + "\n"
79    py_msg += "Version:  " + platform.python_version()  + "\n"
80    py_msg += "Implementation:  " + platform.python_implementation()  + "\n"
81    py_msg += "Compiler:  " + platform.python_compiler()  + "\n"
82
83
84    logger.info(os_msg)
85    logger.info(cpu_msg)
86    logger.info(ram_msg)
87    logger.info(gpu_msg)
88    logger.info(py_msg)